package models

import (
	"time"
	"user-srv/basic/inits"
)

type UserPointsLog struct {
	Id        uint32    `gorm:"column:id;type:int UNSIGNED;primaryKey;not null;" json:"id"`
	UserId    uint32    `gorm:"column:user_id;type:int UNSIGNED;comment:用户ID;not null;" json:"user_id"`                         // 用户ID
	Points    uint32    `gorm:"column:points;type:int UNSIGNED;comment:变动积分 （正数为增加，负数为减少);not null;" json:"points"` // 变动积分 （正数为增加，负数为减少)
	Type      string    `gorm:"column:type;type:varchar(255);comment:积分类型：income 收入 expense支出;not null;" json:"type"`     // 积分类型：income 收入 expense支出
	Reason    string    `gorm:"column:reason;type:varchar(255);comment:变动原因;not null;" json:"reason"`                         // 变动原因
	CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null;default:CURRENT_TIMESTAMP;" json:"created_at"`
}

func (u *UserPointsLog) TableName() string {
	return "user_points_log"
}
func (u *UserPointsLog) AddUserPointsLog() error {
	return inits.DB.Create(&u).Error
}
